# https://bazel.build/concepts/platforms-intro
# https://bazel.build/docs/platforms
platform(
    name = "android_arm32",
    constraint_values = [
        "@platforms//os:android",  # https://github.com/bazelbuild/platforms/blob/main/os/BUILD
        "@platforms//cpu:armv7",  # https://github.com/bazelbuild/platforms/blob/main/cpu/BUILD
    ],
)

platform(
    name = "android_arm64",
    constraint_values = [
        "@platforms//os:android",
        "@platforms//cpu:arm64",
    ],
)

platform(
    name = "linux_x64_hermetic",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
        ":use_hermetic_toolchain",
    ],
)

# Based on
# https://skia.googlesource.com/skia/+/0d4fcf388a6f9318e2a54fa85fddf3396d521767/bazel/platform/BUILD.bazel#31.
platform(
    name = "mac_x64_hermetic",
    constraint_values = [
        "@platforms//os:macos",
        "@platforms//cpu:x86_64",
        ":use_hermetic_toolchain",
    ],
)

# Based on
# https://skia.googlesource.com/skia/+/0d4fcf388a6f9318e2a54fa85fddf3396d521767/bazel/platform/BUILD.bazel#40.
platform(
    name = "mac_arm64_hermetic",
    constraint_values = [
        "@platforms//os:macos",
        # The Skia repository uses cpu:arm64, but as of 2023-10-25 that yields a "No matching
        # toolchains found" error on Apple silicon. It could be due to the fact that the Skia and
        # skcms repositories use different Bazel versions.
        "@platforms//cpu:aarch64",
        ":use_hermetic_toolchain",
    ],
)

platform(
    name = "host_with_hermetic_toolchain",
    constraint_values = [
        ":use_hermetic_toolchain",
    ],
    parents = ["@local_config_platform//:host"],
)

# This constraint allows us to force Bazel to resolve our hermetic toolchain to build
# the target and not a default one (e.g. on the Linux RBE instance). We do this by
# adding the constraint to our platforms that describe the target we want Bazel to build for.
# https://bazel.build/reference/be/platform#constraint_setting
constraint_setting(name = "skcms_hermetic_toolchain")

constraint_value(
    name = "use_hermetic_toolchain",
    constraint_setting = ":skcms_hermetic_toolchain",
    visibility = ["//visibility:public"],
)
